#region Using References

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Beaker.OpenCube.CubeManager.Model.Framework;
using Beaker.OpenCube.CubeManager.Model.Interfaces;

#endregion

namespace Beaker.OpenCube.CubeManager.Model.Entities
{
	public class Server
		: Entity, INamed
	{
		private Machine _hostingMachine;
		private readonly EntitySet<RoleSet, Server> _roleSets; 

		public Server( string serverName )
			: this()
		{
			Name = serverName;
		}

		internal Server()
		{
			_roleSets = new EntitySet<RoleSet, Server>( this );
		}

		/// <summary>
		/// Gets the name of the server.
		/// </summary>
		/// <value>
		/// The name of the server.
		/// </value>
		[StringLength( 64 ), Required]
		public string Name { get; internal set; }

		/// <summary>
		/// Gets the megabytes of memory for this server.
		/// </summary>
		/// <value>
		/// The megabytes of memory for this server.
		/// </value>
		[Required]
		public int MegabytesOfMemory { get; internal set; }

		/// <summary>
		/// Gets the full name of the domain.
		/// </summary>
		/// <value>
		/// The full name of the domain, or <c>null</c> when not set.
		/// </value>
		[StringLength(253)]
		public string FullDomainName { get; internal set; }

		/// <summary>
		/// Gets or sets the port number the server is hosted on.
		/// </summary>
		/// <value>
		/// The port number the server is hosted on.
		/// </value>
		[Required]
		public int PortNumber { get; internal set; }

		/// <summary>
		/// Gets or sets the maximum number of players.
		/// </summary>
		/// <value>
		/// The maximum number of players.
		/// </value>
		public int MaxPlayers { get; internal set; }

		/// <summary>
		/// Gets the machine that hosts this server.
		/// </summary>
		/// <value>
		/// The hosting machine that hosts this server.
		/// </value>
		public Machine HostingMachine
		{
			get { return _hostingMachine; }
			internal set { SetAndSync( ref _hostingMachine, value, m => m.Servers ); }
		}

		/// <summary>
		/// Gets the set of rolesets for this server
		/// </summary>
		public ISet<RoleSet> RoleSets
		{
			get { return _roleSets; }
		}
	}
}